<script setup lang="ts">

import ConsolePermissionApi from '/@/api/console/ConsolePermissionApi.ts';
import AppUtil from "/@/utils/app.ts";
import treeUtil from "/@/utils/treeUtil.ts";
const selectedMenu = ref(null)
const props = defineProps({
  modelValue:{

  }
})
const emits= defineEmits(['update:modelValue'])
const initData = ()=> {
  if (props.modelValue) {
    try {
      selectedMenu.value =  props.modelValue
    } catch (e) {

    }
  }
}
const handleChange =(data)=> {
  console.log(data);
  emits('update:modelValue',selectedMenu.value)
}
watch(()=>props.modelValue,()=> {
  initData()
})
initData()
const config = {
  optionsFunction: async () => {   //通过函数处理本地数据源  完成组件初始化

    let menus = await ConsolePermissionApi.getListData({type: 0});
    return treeUtil.treeData(menus.data,[],{ id: 'id', parentId: 'pid', children: 'children' });

  },
  props: {   //下拉框数据绑定 映射关系
    label: 'title',
    value: 'id',
    emitPath: false,
    checkStrictly: true
  },
  clearable: true
}


</script>

<template>
  <CommonSelect style="width: 100%;" :config="config" v-model="selectedMenu" @update:modelValue="handleChange"/>
</template>

<style scoped lang="scss">

</style>
